package com.relytosoft.dubhe.common.api.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.relytosoft.dubhe.common.api.entity.system.SysOplog;
import com.relytosoft.dubhe.common.api.mapper.RemoteLogMapper;
import com.relytosoft.dubhe.common.api.service.RemoteLogService;
import com.relytosoft.dubhe.common.core.constant.PropertyConstants;
import com.relytosoft.dubhe.common.datasource.Base;
import com.relytosoft.mizar.media.common.emqx.client.MqttOp;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

/**
 * @author Jierry
 * @version 2022/4/22.
 */
@Service
@Base
@ConditionalOnProperty(prefix = PropertyConstants.PROPERTY_DUBHE_MICROSERVICE, name = "localDB", havingValue = "true")
public class RemoteLogServiceImpl extends ServiceImpl<RemoteLogMapper, SysOplog> implements RemoteLogService {

    @Override
    public void saveOpLog(SysOplog sysOplog) {
        baseMapper.insert(sysOplog);
        MqttOp.publish("mqlog", JSON.toJSONString(sysOplog));
    }
}
